package com.ys.timer;

import com.ys.service.report.ReDeptRevenueExpenditureService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;

@Controller
public class TimerReDeptRevenueExpenditureMonth {
	private static final Logger logger = LoggerFactory.getLogger(TimerReDeptRevenueExpenditureMonth.class);

	@Autowired
	private ReDeptRevenueExpenditureService reDeptRevenueExpenditureService;

	//每月1号12点执行，统计部门业务收支报告
	@Scheduled(cron = "0 0 12 1 * * ")
	public void addReFinanceExamineDaily() {
		try {
			logger.info("***********定时统计部门业务收支报告--开始***********");
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
			//获取当前时间日期
			Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.MONTH, -1);//上个月
			String oldMonth = sdf.format(calendar.getTime());
			reDeptRevenueExpenditureService.countReDeptRevenueExpenditure(oldMonth);
			logger.info("***********定时统计部门业务收支报告--完成***********");
		}catch (Exception e){
			logger.error("定时统计部门业务收支报告出错：",e.getMessage(),e);
		}
	}



	
}
